<template>
  <div>
    <span>{{year + '年' + month + '月' + day + '日' + '星期' + week}}</span>
    <span>{{hour + ':' + minute + ':' + second}}</span>
  </div>
</template>

<script>
  const sd = require('silly-datetime')
  export default {
    name: "CurrentTime",
    data() {
      return {
        currentTime: '',
        // 时间
        timer: "",
        year: new Date().getFullYear(),//小时
        month: new Date().getMonth() + 1,//小时
        day: new Date().getDate(),//小时
        hour: new Date().getHours(),//小时
        minute: String(new Date().getMinutes()).length === 1 ? '0' + new Date().getMinutes() : new Date().getMinutes(),//分钟
        second: String(new Date().getSeconds()).length === 1 ? '0' + new Date().getSeconds() : new Date().getSeconds(),//秒
        week:"日一二三四五六".charAt(new Date().getDay())
      }
    },
    mounted() {
      this.timer = setInterval(() => {
        this.year = new Date().getFullYear()
        this.month = new Date().getMonth() + 1
        this.day = new Date().getDate()
        this.hour = new Date().getHours()
        this.minute = String(new Date().getMinutes()).length === 1 ? '0' + new Date().getMinutes() : new Date().getMinutes()
        this.second = String(new Date().getSeconds()).length === 1 ? '0' + new Date().getSeconds() : new Date().getSeconds()
        this.week = "日一二三四五六".charAt(new Date().getDay())

      }, 1000)
    },
    computed:{
      finalDate(){

      }
    },
    beforDestroy() {
      if (this.timer) {
        clearInterval(this.timer)
      }
    }
  }
</script>

<style scoped>

</style>